<?php
declare(strict_types=1);

namespace App\Resource\Dynamic\Reply;


use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class ChildrenResource extends JsonResource
{
    public function toArray($request)
    {
        Carbon::setLocale('zh');
        return [
            'id' => $this->id,
            'dynamic_id' => $this->dynamic_id,
            'user_id' => $this->user_id,
            'like_count' => $this->like_count,
            'content' => $this->content,
            'reply_to_id' => $this->reply_to_id,
            'reply_user_id' => $this->reply_user_id,
            'reply_user_nickname' => ($this->parent_id != $this->reply_to_id) ? ($this->reply_user->nickname ?? '') : "",
            'parent_id' => $this->parent_id,
            'status' => $this->status,
            'user' => [
                'id' => $this->user->user_id ?? 0,
                'code' => $this->user->user_data->user_code ?? 0,
                'nickname' => $this->user->user_data->nickname ?? '',
                'sex' => $this->user->user_data->sex ?? 0,
                'head_picture' => $this->user->user_data->head_picture ?? '',
                'level_icon' => $this->user->grade->head_picture?? '',
                'decorate' => (!isset($this->user->decorate) || empty($this->user->decorate)) ? (object)[] : $this->user->decorate,
            ],
            'show_at' => Carbon::make($this->created_at)->diffForHumans(),
            'created_at' => Carbon::make($this->created_at)->toDateTimeString(),
        ];
    }
}